import  java.awt.*; 
import  java.awt.event.*; 
import  javax.swing.*; 

public  class  JListComboBox  extends  JFrame  implements  ItemListener  { 
   
   protected  JList  fruits; 
   protected  JComboBox  colors; 
   
   protected  String  items[]  =  {"apple",  "orange",  "banana",  "pear"}; 
   
   public  JListComboBox(){ 
      super("스윙  리스트와  콤보  박스"); 
      getContentPane().setLayout(new  FlowLayout()); 
      
      fruits  =  new  JList(items); 
      fruits.addMouseListener(new  MouseAdapter()  { 
         public  void  mouseClicked(MouseEvent  e){ 
            int  index  =  fruits.locationToIndex(e.getPoint()); 
            if(e.getClickCount()  ==  1){ 
               System.out.println(items[index]); 
            }  else  if(e.getClickCount()  ==  2){ 
               System.out.println("["  +  items[index]  +  "]"); 
            } 
         } 
      }); 
      fruits.setVisibleRowCount(3); 
      JScrollPane  sp  =  new  JScrollPane(fruits); 
      
      colors  =  new  JComboBox(); 
      colors.addItem("white"); 
      colors.addItem("blue"); 
      colors.addItem("green"); 
      colors.addItemListener(this); 
      
      getContentPane().add(sp); 
      getContentPane().add(colors); 
      setDefaultCloseOperation(EXIT_ON_CLOSE); 
      setSize(300,  200); 
      setVisible(true); 
   } 
   
   public  void  itemStateChanged(ItemEvent  e)  { 
      Object  o  =  e.getSource(); 
      if(o  ==  colors){ 
         if(e.getStateChange()  ==  ItemEvent.SELECTED){ 
            Object  data  =  colors.getSelectedItem(); 
            System.out.println(data.toString()); 
         } 
      } 
   } 

   public  static  void  main(String[]  args)  { 
      JListComboBox  jlc  =  new  JListComboBox(); 
   } 
}